<?php
class ControllerModulePromotion extends Controller {
	protected function index($setting) {
		
		if (isset($setting['showTitle'])){
			$this->data['showTitle'] = $setting['showTitle'];
		}else{
			$this->data['showTitle'] = 0;//show
		}
		if (isset($setting['showType'])){
			$this->data['showType'] = $setting['showType'];
		}else{
			$this->data['showType'] = 0;//single
		}
		
		$this->language->load('module/promotion');
 
      	$this->data['heading_title'] = $this->language->get('url_promotion/promotion');
				
		$this->data['button_cart'] = $this->language->get('button_cart');
		
		$this->load->model('promotion/promotion');
		
		$this->load->model('tool/image');

		$this->data['activitys'] = array();

		$results = $this->model_promotion_promotion->getActivitys($setting['limit']);
		
		foreach ($results as $result) {	
			
			if ($result['img']) {
				$image = $this->model_tool_image->resize($result['img'], $setting['image_width'], $setting['image_height']);
			} else {
				$image = '';
			}
										
			$this->data['activitys'][] = array(
				'id'          => $result['id'],
				'name'    	  => $result['name'],
				'description' => $result['description'],
				'startTime'   => $result['start_time'],
				'endTime'     => $result['end_time'],
				'clickNum'    => $result['click_num'],
				'img'         => $image,
				'href'    	  => $this->url->linkRewrite(ROUTE_PROMOTION_R, $result['name'] . '_f' . $result['id']),
			);
		}

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/promotion.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/promotion.tpl';
		} else {
			$this->template = 'default/template/module/promotion.tpl';
		}

		$this->render();
	}
}
?>